package com.herench.bs.handler;

import com.herench.bs.agent.IOutpatientClinicAgent;
import com.herench.bs.annotation.Handler;
import com.herench.bs.support.AbstractMessageHandler;
import com.herench.bs.support.RequestMessage;
import com.herench.bs.support.ResponseMessage;
import com.herench.bs.utils.DataFormatUtils;
import org.springframework.stereotype.Component;

import java.util.Calendar;
import java.util.Map;

/**
 * com.herench.bs.handler
 *
 * @author wangwenkai
 * @date 2017/10/30/15:44
 * E-mail：605064334@qq.com
 * 获取诊间挂号列表
 */
@Component
@Handler(code = "102106" ,name="获取诊间挂号列表")
public class LoadRegistRecordsForClinicChargeHandler extends AbstractMessageHandler {
    @Override
    protected ResponseMessage innerHandler(RequestMessage requestMessage) throws Exception {
        ResponseMessage responseMessage = new ResponseMessage(requestMessage.getId());
        String channelCode = requestMessage.getArgsPropertyStringValue("sysCode");
        String userName = requestMessage.getArgsPropertyStringValue("user");
        String idCard = requestMessage.getArgsPropertyStringValue("idCard");
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.YEAR, -1);
        String startTime = DataFormatUtils.getSimpleTimeString(calendar.getTime());
        calendar.add(Calendar.YEAR, 1);
        calendar.add(Calendar.DAY_OF_YEAR,0);
        String endTime = DataFormatUtils.getSimpleTimeString(calendar.getTime());
        IOutpatientClinicAgent outpatientClinicAgent = getCleverClinicContext().getApplicationContext().getBean(IOutpatientClinicAgent.class);
        String hospitalCode = getCleverClinicContext().getHospitalCodeByChannelCode(channelCode);
        Map<String, Object> res = outpatientClinicAgent.loadRegistRecordsForClinicCharge(channelCode, hospitalCode, startTime, endTime, idCard,userName);
        responseMessage.setData(res);
        getPropertiesFromInvokerResultMap(responseMessage, res);
        return responseMessage;
    }
}
